<?php

	/**
	 * 库存查询
	 * @author QiuXiancCheng
	 * that makes me to 
	 * @date 2016-07-13
	 */
	defined('APPLICATION_PATH') or die;
	class Base_StockController extends Controller_NeedLogin{

		public $stockModel;

		public function init(){

			parent::init();
			$this -> stockModel = new Base_Model_Stock;
			$this -> department = new Base_Model_Department;
			$this -> productCateModel = new Application_Model_ProductCatalog;
			$this -> userModel = new System_Model_User;
			$this -> deptModel = new Base_Model_Department;
		}
		/**
		 * 子仓库存
		 * @author sundongdong
		 * @date 2016-09-30
		 */
		public function indexAction() {
			$params = [];
			$params['page'] = !empty($getData['page']) ? $getData['page'] : 1;
			$params['perPage'] = !empty($getData['page_size']) ? $getData['page_size'] : $this->page_size;
			$params['dept_id'] = $this->getRequest()->getParam('dept_id', '');
			$params['warehouse_id'] = $this->getRequest()->getParam('warehouse_id', '');
			$params['select_cat_id'] = $this->getRequest()->getParam('select_cat_id', '');
			$params['deval'] = $this -> userModel -> getCategoryParents($params['select_cat_id']);
			$params['life_cycle'] = $this->getRequest()->getParam('life_cycle', '');
			$params['search_type'] = $this->getRequest()->getParam('search_type', '1');
			$params['searchName'] = $this->getRequest()->getParam('searchName', '');
			$result = $this->stockModel->getSonStock($params);
			
			$this -> smarty -> assign('param', $params);
			$this -> smarty -> assign('params', json_encode($params));
			$handle = new Base_Model_Department;
			$depts = $handle -> getDepartment();
			$this -> smarty -> assign('depts', $depts);
			$this -> smarty -> assign('sale_day', Backup_Model_Demand::SALE_DATA);
			$this->smarty->assign('stock', $result['list']);
			$this->smarty->assign('page', $this->page($result['count'],$params['perPage']));
			$this -> smarty -> display('son_stock_index.php');
		}
		/**
		 * 总仓库存
		 * @author sundongdong
		 * @date 2016-09-30
		 */
		public function basestocksAction() {
			$params = [];
			$params['page'] = !empty($getData['page']) ? $getData['page'] : 1;
			$params['perPage'] = !empty($getData['page_size']) ? $getData['page_size'] : $this->page_size;
			$params['select_cat_id'] = $this->getRequest()->getParam('select_cat_id', '');
			$params['deval'] = $this -> userModel -> getCategoryParents($params['select_cat_id']);
			$params['search_type'] = $this->getRequest()->getParam('search_type', '1');
			$params['searchName'] = $this->getRequest()->getParam('searchName', '');
			
			$result = $this->stockModel->getSumStock($params);
			
			$this -> smarty -> assign('params', $params);
			$this->smarty->assign('stock', $result['list']);
			$this->smarty->assign('page', $this->page($result['count'],$params['perPage']));
			$this -> smarty -> display('base_stock_index.php');
		}

		/**
		 * 计算可用库存
		 * 计算公式为“仓库真实库存+在途库存-订单占用量”。
		 * （其中“订单占用量”在后台数据库表中存计算公式为“仓库真实库存+在途库存-订单占用量”。
		 * （其中“订单占用量”在后台数据库表中存在，由OMS传输过来；仓库真实库存=可配库存+待发库存）
		 */
		public function computeBaseStock(){}
	}